(ns ken.pu.main.build-all-index
 (:use [ken.pu.lucene-helper]
       [ken.pu.mycampus-helper]))

(defn main []
  (do
    (let [writer (mk-index-writer "mycampus-entities.idx")
          index (fn [ent row]
                  (index-doc writer 
                    (entity-to-doc
                      (assoc row
                        :entity (:entity ent)
                        :id (:id row)
                        :__all__ (join-values row (:text-attr ent))))))]
      (print "Indexing schedules...")
      (time (crawl-entities *schedule-entity* index))
      (print "Indexing courses...")
      (time (crawl-entities *course-entity* index))
      (print "Indexing persons...")
      (time (crawl-entities *person-entity* index))
      (close-index-writer writer))
    
    ;
    ; Index the values
    ;
    (let [writer (mk-index-writer "mycampus-values.idx")
          index (fn [ent row]
                  (doseq [k (:text-attr ent) :let [v (row (keyword k))]]
                    (index-doc writer (value-to-doc (:entity ent) k v))))]
      (print "Indexing of schedule values...")
      (time (crawl-entities *schedule-entity* index))
      (print "Indexing of course values...")
      (time (crawl-entities *course-entity* index))
      (print "Indexing of person values...")
      (time (crawl-entities *person-entity* index))
      (close-index-writer writer))
   ))

(main)